Repository navigation
Let the Knowledge list go past the newest 200 records - #447
Merged
abhishekgahlot2 merged 1 commit intoNov 13, 2026
Merged
abhishekgahlot2 merged 1 commit into
abhishekgahlot2 merged 1 commit into
Conversation
GET /api/knowledge answered at most 200 records, pinned first and then newest first, with no cursor, so older unpinned records could never be reached from the Knowledge page. The list now pages: - listRecordPage (backend/src/knowledge/store.ts) replaces listRecords, whose only caller was the route. It keeps pinned DESC, created_at DESC, adds id DESC so a page cut between equal timestamps is stable, and reads one row past the limit to know whether another page follows. Every key sorts descending, so "after the cursor" is one row-value comparison. - GET /api/knowledge takes limit (1 to 500, default 200) and cursor, and answers has_more and next_cursor next to records. The cursor (list-cursor.ts) is the last record's pinned flag, created_at as whole microseconds, and id; a malformed one answers 400 "cursor is invalid". Without a cursor the first page is the same 200 as before. - The Knowledge page carries the cursor from the server render. Once every loaded row is showing, Show older knowledge appends the next page without repeating a record. A failed page says so and Try again resends the same cursor; a second click while a page loads sends nothing. After an older page is loaded, a refresh puts the newest page in front and keeps the rest. With a folder filter and more to load, the empty line says "among the loaded records". An old web client ignores the new fields; a new one talking to an old backend gets no next_cursor and shows no button. Docs: the GET /api/knowledge row and a line on Show older knowledge.
Contributor
|
Merged, thanks @officialasishkumar. Marking older pages loaded before the fetch and merging the newest page once they exist keeps every record through a refresh, and loading only on click keeps it bounded. Nicely done. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
By opening this pull request you agree to the Contributor License Agreement. On your first pull request a bot asks you to sign it with a one-line comment.
Fixes #211
GET /api/knowledgeanswered at most 200 records, pinned first and then newest first, with no cursor. Older unpinned records fell outside the Knowledge list, and the page had no way to reach them.What changed
GET /api/knowledgepages (backend/src/knowledge/)limit(1 to 500, default 200, the boundslistRecordsalready had) andcursor. The response now carrieshas_moreandnext_cursornext torecords.next_cursorback ascursor, with the sameqandlimit, to get the records after the page. Without a cursor the first page is the same 200 as before, so current callers and the released web client see no change.listRecordPageinstore.tsreplaceslistRecords(the route was its only caller). It keeps the order the issue asks for,pinned DESC, created_at DESC, withid DESCadded so a page cut between equal timestamps is stable, and reads one row pastlimitto know whether another page follows. Every key sorts descending, so "after the cursor" is one row-value comparison,(pinned, created_at, id) < (cursor), which the existingknowledge_org_listindex(org_id, pinned DESC, created_at DESC)serves.list-cursor.ts) is the last record'spinned,created_atas whole microseconds since the epoch, andid, as base64url JSON. Microseconds come from Postgres and go back as'epoch' + n microseconds, the way the thread relationships cursor does it, so records created within one millisecond are neither repeated nor skipped.400 {"error":"cursor is invalid"}. The query stays scoped to the caller's workspace, so a cursor carries nothing across workspaces.qkeyword filter pages the same way.Knowledge page (
frontend/app/(library)/knowledge/)fetchKnowledgereadsnext_cursor; a missing or empty one means the last page).role="alert"). The button becomes Try again and resends the same cursor, and the records already shown stay.mergeNewestPage). The cursor of the next older page is kept.Docs: the
GET /api/knowledgerow indocs-site/docs/api/knowledge.mdx, and a line on Show older knowledge indocs-site/docs/product/knowledge-and-wiki.mdx.Across a release: an old web client ignores the new fields. A new client talking to an old backend gets no
next_cursor, so the button stays hidden.One limit: once older pages are loaded, a refresh re-reads only the newest page. A record changed elsewhere that sits outside that page (pinned or unpinned in another tab, say) keeps its old state until a reload. That is the same trade-off as Show older files on the Artifacts page.
Tests
backend/test/knowledge-pages.test.ts, through the real route and database. The expected order comes from Postgres directly, not from the code under test.qfilter pages 10 matches as 4, 4, 2, newest firstlimitis held between 1 and 500, and a non-number gives 200pinned, a number or negative or too-large microsecond count, a non-uuid id) each answer 400backend/test/knowledge.test.tsmoves tolistRecordPage.Frontend:
knowledge-gallery.interaction.test.tsxmountsKnowledgeGalleryunder happy-dom with a stubbed fetch:knowledge-api.test.ts: the request paths, a missing, empty or non-string cursor read as the last page, a failed answer thrown,mergeNewestPageandappendOlderPageChecks with Bun 1.3.14, backend tests on
pgvector/pgvector:0.8.6-pg16-bookworm:cd backend && bun run test: 3639 pass, 0 fail, then the Slack suite 119 pass, 0 failbun run typecheck(root): passescd frontend && bun run test: 2012 pass, 0 failcd frontend && bun run lint: 248 warnings and 22 infos, the same asmaincd frontend && bun run build: passescd docs-site && bunx blume validate: no broken linksbun test scripts/agent-docs.test.ts: 5 passEnd to end
I ran a real backend on its own Postgres and a production build of the frontend (
next start), signed in, and added 230 knowledge records, "Fact 0" (oldest) to "Fact 229", with "Fact 3" and "Fact 150" pinned./knowledgeshows Pinned 2 (Fact 150, Fact 3) and All knowledge 198, the first 30 rows, and "Show 168 more". Before this change, Fact 0 to Fact 30 could not be reached on the page.GET /api/knowledge?cursor=…. All knowledge becomes 228, the list ends at "Fact 0", and the button is gone.Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.